﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace ArtsShop.DataLayer.DataAccess
{
    public class ProductFamilyDAO : DataServiceBase
    {
         public ProductFamilyDAO() : base() { }
        /// <summary>
        ///	Creates a new DataService and specifies a transaction with
        ///	which to operate
        /// </summary>
         public ProductFamilyDAO(IDbTransaction txn) : base(txn) { }

        /* public static DataTable retrieveProductImageData(int productFamilyId)
         {
             DataSet productImageDataSet;
             DataTable productImageDataTable;
             
             productImageDataSet = ExecuteDataSet("[dbo].[ProductImage.GetById]", CreateParameter("@productFamilyId", SqlDbType.Int, productFamilyId));
             if ((productImageDataSet!= null) && ((productImageDataTable = productImageDataSet.Tables[0]).Rows.Count > 0))
             {
                 return productImageDataTable;
             }

             return null;
         }

         public static string DeleteProductFamilyImage(int productImageId)
         {
             string errorMessage = string.Empty;

             try
             {
                 //deleteProductFamilyImageProcedure.ExecuteNonQuery();
                 ExecuteDataSet("[dbo].[ProductImage.DeleteById]", CreateParameter("@productImageId", SqlDbType.Int, productImageId));
             }
             catch (SqlException e)
             {
                 errorMessage = e.Message;
                 //	errorMessage = "An error occurred when deleting the product family image";
             }

             return errorMessage;
         }
        */
         public static string UpdateProductFamilyImage(int productImageId, string imageName, bool primaryImage, int? diffProductId)
         {
             string errorMessage = string.Empty;
             /*B4NDatabase.StoredProcedure updateProductImageProcedure = DataBase.Site.BuildStoredProc("[dbo].[ProductImage.UpdateById]");
             ExecuteDataSet("[dbo].[ProductImage.DeleteById]", CreateParameter("@productImageId", SqlDbType.Int, productImageId));
             updateProductImageProcedure.AddInParameter("@productImageId", DbType.Int32, productImageId);
             updateProductImageProcedure.AddInParameter("@imageName", DbType.String, imageName);
             updateProductImageProcedure.AddInParameter("@primaryImage", DbType.Boolean, primaryImage);
             updateProductImageProcedure.AddInParameter("@diffProductId", DbType.Int32, diffProductId);

             try
             {
                 updateProductImageProcedure.ExecuteNonQuery();
             }
             catch (SqlException)
             {
                 errorMessage = "An Error Occurred During the Update";
             }
             */
             return errorMessage;
         }



         internal static string CreateProductFamilyImage(int productFamilyId, string imageName, bool isDefault, int? diffProductId)
         {
             string errorMessage = string.Empty;
            /* B4NDatabase.StoredProcedure createProductFamilyImageProcedure = DataBase.Site.BuildStoredProc("[dbo].[ProductImage.Create]");

             createProductFamilyImageProcedure.AddInParameter("@productFamilyId", DbType.Int32, productFamilyId);
             createProductFamilyImageProcedure.AddInParameter("@imageName", DbType.String, imageName);
             createProductFamilyImageProcedure.AddInParameter("@isDefault", DbType.Boolean, isDefault);
             createProductFamilyImageProcedure.AddInParameter("@diffProductId", DbType.Int32, diffProductId);
             */
             SqlCommand cmd;
             
             try
             {
                 ExecuteNonQuery(out cmd, "[dbo].[ProductImage.Create]",
                CreateParameter("@productFamilyId", SqlDbType.Int, productFamilyId),
                CreateParameter("@imageName", SqlDbType.String, imageName),
                CreateParameter("@isDefault", SqlDbType.Boolean, isDefault),
                CreateParameter("@diffProductId", SqlDbType.Int32, diffProductId));
             }
             catch (SqlException)
             {
                 errorMessage = "";
             }
             cmd.Dispose();
             return errorMessage;
         }
    }
}
